package priv.lirenhe.exam02.B;

import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Example10{
    public static void main(String[] args) throws IOException {
    	/*InetAddress ia = InetAddress.getLocalHost();
    	System.out.println(ia.getHostAddress());
    	System.out.println(ia.getHostName());
    	System.out.println(ia.isReachable(3000));*/
    
        URL url = null;
        URLConnection urlconn = null;
        BufferedReader br = null;
        PrintWriter pw = null;
        try {
            url = new URL("http://www.hualixy.com/Overview.asp?id=34&mnid=1");
            urlconn = url.openConnection();
            pw = new PrintWriter(new FileWriter("./siteSource.html"), true);
            br = new BufferedReader(new InputStreamReader(
                    urlconn.getInputStream()));
            String buf = null;
            while ((buf = br.readLine()) != null) {
            	System.out.println(buf.toString());
            	pw.println(buf);
            }
            System.out.println("爬取成功^_^");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            pw.close();
        }
    }
}